
#include <mxml.h>


#define NODE_NAME_CHINA 		"China"
#define NODE_NAME_CITY			"City"
#define NODE_NAME_NAME			"Name"
#define NODE_NAME_AREA			"Area"
#define NODE_NAME_POPULATION	"Population"
#define ATTRIBUTE_NAME_ISBIG	"isbig"


int main()
{

	// 创建 xml 文件头节点
	mxml_node_t * xml = mxmlNewXML("1.0");

	// 创建 根节点
	mxml_node_t * node_china = mxmlNewElement(xml, NODE_NAME_CHINA);

	// 创建城市节点
	mxml_node_t * node_city = mxmlNewElement(node_china, NODE_NAME_CITY);
	/* 子节点 */
	mxml_node_t * node_name = mxmlNewElement(node_city, NODE_NAME_NAME);	// 城市
	mxmlElementSetAttr(node_name, ATTRIBUTE_NAME_ISBIG, "true");	// 设置属性
	mxmlNewText(node_name, 0, "北京");		// 标签值

	mxml_node_t *	node_area = mxmlNewElement(node_city, NODE_NAME_AREA);	// 面积
	mxmlNewText(node_area, 0, "1.641万平方千米");

	mxml_node_t *	node_population = mxmlNewElement(node_city, NODE_NAME_POPULATION);	// 人口
	mxmlNewText(node_population, 0, "2200万");

	
	node_city = mxmlNewElement(node_china, NODE_NAME_CITY);

	node_name = mxmlNewElement(node_city, NODE_NAME_NAME);
	mxmlElementSetAttr(node_name, ATTRIBUTE_NAME_ISBIG, "false");
	mxmlNewText(node_name, 0, "石家庄");

	node_area = mxmlNewElement(node_city, NODE_NAME_AREA);
	mxmlNewText(node_area, 0, "15848平方千米");

	node_population = mxmlNewElement(node_city, NODE_NAME_POPULATION);
	mxmlNewText(node_population, 0, "170万");

	/* 保存到字符串输出 */
	char buff[4096];
	mxmlSaveString(xml, buff, 4096, MXML_NO_CALLBACK);
	printf("%s\n", buff);

	FILE *fp = fopen("China.xml","w");
	mxmlSaveFile(xml, fp, MXML_NO_CALLBACK);

	fclose(fp);
	mxmlDelete(xml);
	

	return 0;
}


